<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>首页</title>
    <link rel="stylesheet" href="./units/swiper-bundle.min.css">
    <link rel="stylesheet" href="./Css/index.css">
    <script src="./units/jquery-3.6.0.js"></script>
</head>

<body>
    <div class="frame">
        <h1>11</h1>
        <div class="left">
            <div class="swiper">
                <div class="swiper-wrapper">
                    <div class="swiper-slide">
                        <img src="./images/海贼王1.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王2.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王3.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王4.gif" alt="" />
                    </div>
                </div>
            </div>
            <div class="swiper">
                <div class="swiper-wrapper">
                    <div class="swiper-slide">
                        <img src="./images/海贼王1.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王2.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王3.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王4.gif" alt="" />
                    </div>
                </div>
            </div>
            <div class="swiper">
                <div class="swiper-wrapper">
                    <div class="swiper-slide">
                        <img src="./images/海贼王1.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王2.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王3.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王4.gif" alt="" />
                    </div>
                </div>
            </div>
            <div class="swiper">
                <div class="swiper-wrapper">
                    <div class="swiper-slide">
                        <img src="./images/海贼王1.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王2.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王3.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王4.gif" alt="" />
                    </div>
                </div>
            </div>
        </div>
        <div class="M">
            <hr>
            <h2>登录</h2>
            <div class="btn">
                账号：<input name="username" type="text" id="user1">
                <br>
                密码：<input name="password" type="password" id="pass1">
                <button id="btn1">登录</button>
            </div>
            <span>&nbsp;</span>
            <span>&nbsp;</span>
            <h2>注册</h2>
            <div class="btn">
                账号：<input name="username" type="text" id="user2">
                <br>
                密码：<input name="password" type="password" id="pass2">
                <button id="btn2">注册</button>
            </div>
            <span>&nbsp;</span>
            <hr>
        </div>
        <div class="right">
            <div class="swiper">
                <div class="swiper-wrapper">
                    <div class="swiper-slide">
                        <img src="./images/海贼王1.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王2.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王3.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王4.gif" alt="" />
                    </div>
                </div>
            </div>
            <div class="swiper">
                <div class="swiper-wrapper">
                    <div class="swiper-slide">
                        <img src="./images/海贼王1.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王2.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王3.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王4.gif" alt="" />
                    </div>
                </div>
            </div>
            <div class="swiper">
                <div class="swiper-wrapper">
                    <div class="swiper-slide">
                        <img src="./images/海贼王1.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王2.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王3.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王4.gif" alt="" />
                    </div>
                </div>
            </div>
            <div class="swiper">
                <div class="swiper-wrapper">
                    <div class="swiper-slide">
                        <img src="./images/海贼王1.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王2.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王3.webp" alt="" />
                    </div>
                    <div class="swiper-slide">
                        <img src="./images/海贼王4.gif" alt="" />
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="./units/swiper-bundle.min.js"></script>
    <script src="./JS/swiper.js"></script>
    <script>
        /*
            jq的ajax的用法
            $.ajax({
                url:'地址、接口',
                data:{}  //给后台的数据
                methods:'get,post'  默认是get
                success:(res)=>{
                    //res就是后台给我们的数据
                }
            })
        */
        const oBtn1 = document.querySelector('#btn1');
        const oPass1 = document.querySelector('#pass1');
        const oUser1 = document.querySelector('#user1');
        const oBtn2 = document.querySelector('#btn2');
        const oPass2 = document.querySelector('#pass2');
        const oUser2 = document.querySelector('#user2');
        //登录
        oBtn1.onclick = function () {
            //发送ajax
            $.ajax({
                url: '/login',
                method: 'post',
                data: {
                    username: oUser1.value,
                    password: oPass1.value
                },
                success: (res) => {
                    if (res.error == 0) {
                        console.log(res)
                        alert(res.msg)
                        // open("news.html")
                        location.href = 'news.html';
                    } else {
                        console.log(res)
                        alert(res.msg)
                    }
                }
            })
        }
        //注册
        oBtn2.onclick = function () {
            $.ajax({
                url: '/register',
                data: {
                    username: oUser2.value,
                    password: oPass2.value
                },
                method: 'post',
                success: (res) => {
                    console.log(res);
                    alert(res.msg)
                }
            })
        }

    </script>
</body>

</html>